﻿/*
 * VerbalExpressions Qt Library v0.1
 * https://github.com/VerbalExpressions/QtVerbalExpressions
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 Skhaz
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef _QVerbalExpressions_h
#define _QVerbalExpressions_h

#define QT_USE_QSTRINGBUILDER

#include <QChar>
#include <QString>
#include <QRegularExpression>

#ifdef Q_COMPILER_INITIALIZER_LISTS
#include <initializer_list>
#endif

#include <qqthighgrade_global.h>

class QQTHIGHGRADESHARED_EXPORT QQtVerbalExpressions
{
public:
    QQtVerbalExpressions();
    QQtVerbalExpressions ( const QQtVerbalExpressions& other );
    QQtVerbalExpressions& operator= ( const QQtVerbalExpressions& other );

#ifdef Q_COMPILER_RVALUE_REFS
    QQtVerbalExpressions ( const QQtVerbalExpressions&& other );
    QQtVerbalExpressions& operator= ( const QQtVerbalExpressions&& other );
#endif

    QQtVerbalExpressions& add ( const QString& value = QString() );
    QQtVerbalExpressions& startOfLine ( bool enable = true );
    QQtVerbalExpressions& endOfLine ( bool enable = true );
    QQtVerbalExpressions& then ( const QString& value );
    QQtVerbalExpressions& find ( const QString& value );
    QQtVerbalExpressions& maybe ( const QString& value );
    QQtVerbalExpressions& anything();
    QQtVerbalExpressions& anythingBut ( const QString& value );
    QQtVerbalExpressions& something();
    QQtVerbalExpressions& somethingBut ( const QString& value );
    QQtVerbalExpressions& lineBreak();
    QQtVerbalExpressions& br();
    QQtVerbalExpressions& tab();
    QQtVerbalExpressions& word();
    QQtVerbalExpressions& anyOf ( const QString& value );
    QQtVerbalExpressions& any ( const QString& value );
    QQtVerbalExpressions& addModifier ( char modifier );
    QQtVerbalExpressions& removeModifier ( char modifier );
    QQtVerbalExpressions& withAnyCase ( bool enable = true );
    QQtVerbalExpressions& searchOneLine ( bool enable = true );
    QQtVerbalExpressions& searchGlobal ( bool enable = true );
    QQtVerbalExpressions& multiple ( const QString& value );
    QQtVerbalExpressions& alt ( const QString& value );

    bool test ( const QString& value );
    QString& replace ( QString& m_source, const QString& value );
#ifdef Q_COMPILER_INITIALIZER_LISTS
    QQtVerbalExpressions& range ( const std::initializer_list<QString>& args );
#endif

    const QString& pattern() const { return m_pattern; }
    const QString& prefix() const { return prefixes; }
    const QString& suffix() const { return suffixes; }
    const QString& source() const { return m_source; }
    //不带const的，用于直接修改
    QString& pattern() { return m_pattern; }
    QString& prefix() { return prefixes; }
    QString& suffix() { return suffixes; }
    QString& source() { return m_source; }

private:
    QString prefixes;
    QString m_source;
    QString suffixes;
    QString m_pattern;
    QRegularExpression::PatternOptions modifiers;
};

QQTHIGHGRADESHARED_EXPORT QDebug& operator<< ( QDebug& debug, const QQtVerbalExpressions& expression );

#endif
